
#import "PUMyAlbumDeleteView.h"
#import "PUPDMoreCell.h"
#import "PUMoreModel.h"

#define SCREENW     [UIScreen mainScreen].bounds.size.width
@interface PUMyAlbumDeleteView ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>{
    UIView *contentView;
}
@property (nonatomic,strong) UICollectionView *collectView;
@property (nonatomic,strong) NSMutableArray *BGArray;
@property (nonatomic,retain) UIView *nohahaAlphaView;
@property (nonatomic)int isJB;
@end
@implementation PUMyAlbumDeleteView


- (instancetype)initCPPDMoreViewViewWith:(NSArray *)data{

    if (self = [super init]) {
        self.BGArray=[NSMutableArray arrayWithArray:data];
        self.frame = [UIScreen mainScreen].bounds;
    }
    [self initAppreaence];
    return self;
}

- (instancetype)initCPPDMoreViewViewWith:(NSArray *)data isJB:(int)isJB{
    if (self = [super init]) {
        self.BGArray=[NSMutableArray arrayWithArray:data];
        self.isJB=isJB;
        self.frame = [UIScreen mainScreen].bounds;
    }
    [self initAppreaence];
    return self;
}


-(void)moreGesture{
    [self dismiss];
}
-(void)nohahaAlphaViewGesture{
    [self dismiss];
}

#pragma mark - initAppreaence
- (void)initAppreaence {
    
    
    self.nohahaAlphaView = [[UIView alloc]init];
    self.nohahaAlphaView.frame =self.bounds;
    self.nohahaAlphaView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.nohahaAlphaView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(nohahaAlphaViewGesture)];
    self.nohahaAlphaView.userInteractionEnabled=YES;
    [self.nohahaAlphaView addGestureRecognizer:tap];
    
    
    contentView = [[UIView alloc] init];
//    contentView.frame=CGRectMake(0, self.frame.size.height, self.frame.size.width, self.frame.size.width*0.544);
//    contentView.frame=CGRectMake(0, self.frame.size.height, self.frame.size.width, self.frame.size.width*0.56);
    if ([self isPhoneX]) {
        contentView.frame=CGRectMake(0, self.frame.size.height, self.frame.size.width, self.frame.size.width*0.517+20);
    }else{
        contentView.frame=CGRectMake(0, self.frame.size.height, self.frame.size.width, self.frame.size.width*0.517);
    }
    contentView.frame=CGRectMake(0, self.frame.size.height, self.frame.size.width, 150);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:contentView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = contentView.bounds;
    maskLayer.path = maskPath.CGPath;
    contentView.layer.mask = maskLayer;
    contentView.backgroundColor=[UIColor whiteColor];
    
   
    [self addSubview:contentView];
    
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.50];
    //添加白色view
    
//    UIView *whiteView = [[UIView alloc] init];
//    whiteView.frame=CGRectMake(0, 0, self.frame.size.width, 60);
//    whiteView.backgroundColor = [UIColor colorWithHex:0xF6F6F6];
//    whiteView.backgroundColor = [UIColor blueColor];
//    [contentView addSubview:whiteView];
    
//    UILabel *lab=[[UILabel alloc]init];
//    lab.frame=CGRectMake(80, 20, _window_width-160, 20);
//    lab.text=@"选择分享方式";
//    lab.font=[UIFont systemFontOfSize:14];
//    lab.textAlignment=NSTextAlignmentCenter;
//    lab.textColor=[UIColor colorWithHex:0x707070];
//    [whiteView addSubview:lab];
    
    UIButton *delectBtn=[UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame=CGRectMake(0, contentView.frame.size.height*0.789, self.frame.size.width, contentView.frame.size.height-contentView.frame.size.height*0.789);
    delectBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [delectBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [delectBtn setTitle:@"删除" forState:UIControlStateNormal];
    [delectBtn addTarget:self action:@selector(delectBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:delectBtn];
    
    if (self.isJB==1) {
        [delectBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [delectBtn setTitle:@"举报" forState:UIControlStateNormal];
    }
    
    
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame=CGRectMake(0, contentView.frame.size.height*0.789, self.frame.size.width, contentView.frame.size.height-contentView.frame.size.height*0.789);
    button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitle:@"取消" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:button];
    
    
    UIView *xianView = [[UIView alloc] init];
//    xianView.frame=CGRectMake(0, contentView.frame.size.height*0.789, self.frame.size.width, 1);
    xianView.backgroundColor = [UIColor colorWithHex:0xF2F2F2];
    [contentView addSubview:xianView];
    

    delectBtn.frame=CGRectMake(0, contentView.frame.size.height-150, self.frame.size.width, 75);
    button.frame=CGRectMake(0, contentView.frame.size.height-75, self.frame.size.width, 75);
    xianView.frame=CGRectMake(0, contentView.frame.size.height-75, self.frame.size.width, 1);
}

- (BOOL)isPhoneX {
    BOOL iPhoneX = NO;
//  if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {//判断是否是手机
//        return iPhoneX;
//    }
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            iPhoneX = YES;
        }
    }
    return iPhoneX;
}

#pragma mark - Actions
- (void)buttonClicked:(UIButton *)sender {
    [self dismiss];
}

#pragma mark - pickerView出现
- (void)show {
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [UIView animateWithDuration:0.2 animations:^{
        
//        if ([self isPhoneX]) {
//            self->contentView.center = CGPointMake(self.frame.size.width/2, self->contentView.center.y - self->contentView.frame.size.height-44);
////            self->contentView.frameHeight=self->contentView.frameHeight+10;
//        }else{
            self->contentView.center = CGPointMake(self.frame.size.width/2, self->contentView.center.y - self->contentView.frame.size.height);
//        }
     
    }];
}

#pragma mark - pickerView消失
- (void)dismiss{
    [self->contentView removeFromSuperview];
    self->contentView=nil;
    [self removeFromSuperview];
    
//    [UIView animateWithDuration:0.1 animations:^{
//        self->contentView.center = CGPointMake(self.frame.size.width/2, self->contentView.center.y + self->contentView.frame.size.height);
//    } completion:^(BOOL finished) {
//        [self removeFromSuperview];
//    }];
}

-(void)delectBtnClicked{
    [self dismiss];
    if ([self.delegate respondsToSelector:@selector(CPMyAlbumDeleteViewdelectBtnClicked)]) {
        [self.delegate CPMyAlbumDeleteViewdelectBtnClicked];
    }
}

@end
